<template>
  <div class="indexPoll-page app-container">
    <div style="margin-bottom: 10px;">
      <el-button type="danger" size="small" @click="addOrUpdateEmailHandle()">
        添加
      </el-button>
    </div>
    <el-table
      :data="list"
      fit
      size="mini"
      max-height="637"
      :header-cell-style="{ background: '#dcedff', color: '#32639d' }"
      style="width: 100%;"
    >
      <el-table-column
        type="index"
        label="序号"
        align="center"
        width="60"
      ></el-table-column>
      <el-table-column
        prop="organName"
        label="邮件名称"
        align="center"
      ></el-table-column>
      <el-table-column label="操作" width="350" align="center">
        <template slot-scope="{ row }">
          <el-button
            class="filter-item"
            size="mini"
            style="margin-left: 10px;"
            type="primary"
            icon="el-icon-edit"
            @click="addOrUpdateEmailHandle(row)"
          >
            编辑
          </el-button>
          <el-button
            class="filter-item"
            size="mini"
            style="margin-left: 10px;"
            type="primary"
            icon="el-icon-delete"
            @click="delectEmailHandle(row)"
          >
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <emailOpen ref="emailOpen" @openClose="findAllOrgan"></emailOpen>
  </div>
</template>

<script>
import { findAllOrgan, deleteInvestOrganById } from '@/api/setting'
import emailOpen from './emailOpen'

export default {
  name: 'EmailTemplate',
  components: { emailOpen },
  data() {
    return {
      dataForm: {
        emailName: '',
      },
      list: [],
    }
  },
  created() {
    this.findAllOrgan()
  },
  methods: {
    addOrUpdateEmailHandle(row) {
      this.$refs.emailOpen.init(row)
    },
    delectEmailHandle(row) {
      this.$confirm('确认删除？', '提示', {
        customClass: 'del-model',
        type: 'warning',
      })
        .then((_) => {
          row.deleteFlag = 0
          deleteInvestOrganById({
            ...row,
          }).then((res) => {
            if (res.code == 0) {
              this.$notify({
                message: res.body,
                type: 'success',
                duration: 2000,
              })
              this.findAllOrgan()
            }
          })
        })
        .catch((_) => {})
    },
    resetForm() {
      this.$refs.dataForm.resetFields()
      this.findAllOrgan()
    },
    findAllOrgan() {
      findAllOrgan().then((res) => {
        this.list = res.body
      })
    },
  },
}
</script>
<style lang="scss" scoped>
.app-container {
  padding: 20px;
}
</style>
